<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        #box {
            width: 600px;
            margin: 50px auto;
        }
        
        .search {
            padding-left: 10px;
            height: 30px;
            line-height: 30px;
            border: 1px solid black;
        }
        
        .search>input {
            /* padding-left: 10px; */
            outline: none;
            width: 400px;
            border: none;
        }
        
        .search>span {
            width: 100px;
            text-align: center;
            display: block;
            float: right;
            background-color: gray;
        }
        
        ul {
            width: 100%;
            border: 1px solid black;
        }
        
        li {
            padding: 5px 0;
            list-style: none;
        }
        
        .active {
            background-color: pink;
        }
    </style>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="js/vue-resource.js"></script>
    <div id="box">
        <div class="search">
            <input type="text" placeholder=" 输入" @input="change" v-model='word' @keydown.down="down" @keydown.up="up">
            <span>百度一下</span>
        </div>
        <ul>
            <li v-for="(item,index) in arr" :class="{active:arrindex==index}">
                {{item}}
            </li>
        </ul>
    </div>

    <script>
        let vm = new Vue({
            el: "#box",
            data: {
                word: '',
                arr: [],
                arrindex: 0
            },
            methods: {
                change() {
                    var url = 'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?'
                    this.$http.jsonp(url, {
                        params: {
                            wd: this.word
                        },
                        jsonp: 'cb'
                    }).then(function(response) {

                        this.arr = response.body.s
                        console.log(this.arr);

                    });;
                },
                down() {
                    this.arrindex++;
                    if (this.arrindex == 9) {
                        this.arrindex = 0
                    }
                },
                up() {
                    console.log(1);
                    if (this.arrindex == 0) {
                        this.arrindex = 9
                    }
                }
            },

        })
    </script>
</body>

</html>